package common;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MethodGetter {
	
	public static Object getValue(Object obj, String methodName, Class<?>[] args){	
		return invokeMethod(obj, getMethod(obj, methodName, args), args);
	}
	
	public static Method getMethod(Object obj, String methodName, Class<?>[] args){
		Method method = null;
		try {
			method = obj.getClass().getDeclaredMethod(methodName, args);
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return method;
	}
	
	public static Object invokeMethod(Object obj, Method method, Class<?>[] args){
		Object val = null;
		try {
			val = method.invoke(obj, args);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return val;
	}
	
}
